﻿//12.Write a program that removes from a text file all words listed in given another text file. Handle all possible exceptions in your methods.

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;


namespace RemoveWords
{
    class RemoveWords
    {
        static List<string> ReadList()
        {
            StreamReader readList = new StreamReader("removewords.txt");
            string word = readList.ReadLine();
            List<string> words = new List<string>();

            using (readList)
            {
                while (word != null)
                {
                    words.Add(word);
                    word = readList.ReadLine();
                }
            }
            return words;
        }


        static void Main()
        {
            try
            {
                StreamReader readText = new StreamReader("text.txt");
                string line = readText.ReadLine();

                List<string> words = ReadList();
                using (readText)
                {
                    while (line != null)
                    {
                        for (int i = 0; i < words.Count; i++)
                        {
                            string word = words[i];
                            line = line.Replace(word, "");
                        }
                        Console.WriteLine(line);
                        line = readText.ReadLine();
                    }
                }
            }

            catch (FileNotFoundException exc)
            {
                Console.WriteLine(exc.Message);
            }
            catch (DirectoryNotFoundException exc)
            {
                Console.WriteLine(exc.Message);
            }
            catch (ArgumentNullException exc)
            {
                Console.WriteLine(exc.Message);
            }
            catch (ArgumentException exc)
            {
                Console.WriteLine(exc.Message);
            }
            catch (OutOfMemoryException exc)
            {
                Console.WriteLine(exc.Message);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
        }
    }
}
